﻿package com.shangda.service;

import java.util.ArrayList;
import java.util.List;

import com.shangda.dao.SewageDao;
import com.shangda.dao.impl.DataSaveImpl;
import com.shangda.dao.impl.SewageDaoImpl;
import com.shangda.entity.ReceiveData;
import com.shangda.entity.Sewage;

public class DataService {
	private SewageDao sewageDao;
	private DataSaveImpl dataSaveImpl;
	
	public DataService(){
		sewageDao = new SewageDaoImpl();
		dataSaveImpl = new DataSaveImpl();
	}
	
	//原数据的保存8990
	public boolean DataSaveOrgin(List<ReceiveData> receiveDatas) throws Exception{
		//0:sewage中不存在sewageId； 1： 插入成功  ; 2: 插入失败
		
		boolean  flag = true;
		
		if (!sewageDao.isExist(receiveDatas.get(0).getSewageId())){
			return false;
		}
		
		
		
		//插入数据库
		//插入到数据库中
	    flag = dataSaveImpl.dataInsertOrgin(receiveDatas);
	    
	    return flag;
	}
	
	
	
	
	//江都数据的保存 8991
	public int DataSave(List<ReceiveData> receiveDatas) throws Exception{
		//0:sewage中不存在sewageId； 1： 插入成功  ; 2: 插入失败
		
		
		//根据sewageID查找sewage,如果存在则插入否则返回0;
		/*boolean flag = sewageDao.isExist(receiveDatas.get(0).getSewageId());
		if (!flag){
			return 0;
		}*/
		
		//插入到数据库中
		boolean flag = dataSaveImpl.dataInsert(receiveDatas);
		
		if (!flag){
			return 2;
		}
			
		
		return 1;
	}
	
	
	//面源污染数据的保存 9990
	public int DataSaveAS(List<ReceiveData> receiveDatas) throws Exception {
		// 0:sewage中不存在sewageId； 1： 插入成功 ; 2: 插入失败

		// 根据sewageID查找sewage,如果存在则插入否则返回0;
		boolean flag = sewageDao.isExist(receiveDatas.get(0).getSewageId());
		if (!flag) {
			return 0;
		}

		// 插入到数据库中
		flag = dataSaveImpl.dataInsertAS(receiveDatas);

		if (!flag) {
			return 2;
		}

		return 1;
	}
	
	
	
	
	public Sewage findSewageById(int sewageId) throws Exception{
		return sewageDao.findById(sewageId);
	}
	
	//跟新sewage数据
	
	public boolean updateSewage(int sewageId,int ... times) throws Exception{
		return sewageDao.updateRunTime(sewageId, times);
	}
	
	

}
